package com.lexin.engine.hive.udf;

import org.apache.hadoop.hive.ql.exec.UDF;

/*
 *
 */
public class SearchPhotoUDF  extends UDF {


    public SearchPhotoUDF() {
        super();
    }

    public String evaluate(String fp1,String fp2, int type){

        StringBuffer sb = new StringBuffer();

        if(fp1 != null && !"".equals(fp1) && fp2 != null && !"".equals(fp2)){
            char[] fp1Char = fp1.toCharArray();
            char[] fp2Char = fp2.toCharArray();

            int fp1CharLength = fp1Char.length;
            int fp2CharLength = fp1Char.length;

            int number = 0;
            if(fp1CharLength == fp2CharLength){
                for (int i = 0; i < fp1CharLength; i++) {
                    if(fp1Char[i] == fp2Char[i]){
                        continue;
                    } else {
                        number ++;

                        if(number > type){
                            return "NG";
                        }
                    }
                }

                if(number <= type){
                    return "OK";
                }
            }

        }

        return "NG";
    }

    public static void main(String[] args) {
        String fp1 = "ooakooooojaemdaajaaaoaaaooonooonooooooojooojodabjaabjaabjaabdaaa";
        String fp2 = "qoakooooojaemdaajaaaoaaaooonooonooooooojooojodabjaabjaabjaabdaaa";

        System.out.println(new SearchPhotoUDF().evaluate(fp1,fp2,1));
    }
}
